home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.08 Aug 91 / ListHandler Code / IconicLDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-23  |  1.8 KB  |  67 lines  |  [TEXT/KAHL]

  1. /*                                            Iconic LDEF.c                                        */
  2. /*
  3.  * All of the list-drawing nitty-gritty is here.
  4.  * Each list cell contains an icon and the icon id.
  5.  * Either draw the icon in the cell rectangle or convert
  6.  * the icon id to hex and draw that string.
  7.  *
  8.  * Copyright © 1989, 1990 Martin Minow and MacTutor.
  9.  */
  10. #include "IconicLDEF.h"
  11.  
  12. void iconicLDEF(Rect *, Cell, short, short, ListHandle);
  13. static void    DrawHex(unsigned short, short);
  14.  
  15. /*
  16.  * iconicLDEF() is called by the LDEF handler to draw
  17.  * an icon whose resource ID is stored in the cell.
  18.  */ 
  19. void
  20. iconicLDEF(rect, cell, offset, length, list)
  21. Rect                *rect;            /* Rectangle to draw cell in        */
  22. Cell                cell;                /* The selected cell                        */
  23. short                offset;            /* Start of data in the list        */
  24. short                length;            /* Number of bytes to draw            */
  25. ListHandle    list;                /* The list itself.                            */
  26. {
  27.         IconInfo    iconInfo;
  28.  
  29.         /*
  30.          * Note that we ignore zero-length (empty) cells.
  31.          */
  32.         if (length == sizeof iconInfo) {
  33.             LGetCell(&iconInfo, &length, cell, list);
  34.             /*
  35.              * Show we can access the global parameter.  Of
  36.              * course, a "real" application would use a
  37.              * document-specific data structure, probably
  38.              * accessed via the document structure or window
  39.              * refCon.  Using this global is actually incorrect
  40.              * as partial window updates will leave a list cell
  41.              * half in one format and half in the other.
  42.              */
  43.             if (drawAsText)
  44.                 DrawHex(iconInfo.number, sizeof (short) * 2);
  45.             else {
  46.                 if (iconInfo.handle != NIL) {
  47.                     PlotIcon(rect, iconInfo.handle);
  48.                 }
  49.             }
  50.         }
  51. }
  52.  
  53. /*
  54.  * Recursive routine to draw a value in hex.
  55.  * Each call of DrawHex outputs one nibble.
  56.  */
  57. static void
  58. DrawHex(hex, size)
  59. unsigned short        hex;
  60. short                            size;
  61. {
  62.         if (--size > 0)
  63.             DrawHex(hex >> 4, size);
  64.         hex &= 0x0f;
  65.         DrawChar((hex >= 10) ? hex - 10 + 'a' : hex + '0');
  66. }
  67.